﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portfolio.BL.Common;
using Portfolio.Entities;
using Portfolio.Repository.ArticleCategories;
using Portfolio.BL.Dictionary;

namespace Portfolio.BL.ArticleCategories
{
    /// <summary>
    /// Klasa BL ArticleCategory DropDownList
    /// </summary>
    public class ArticleCategoriesDDLBL : InformationUser 
    {
       // private Portfolio3Entities _context;
        private ArticleCategoriesDDLRepository _articleCategoriesDDLRepository;
        
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="pArticleCategory"></param>
        public ArticleCategoriesDDLBL() : base()
        {
            //_context = new Portfolio3Entities();
            _articleCategoriesDDLRepository = new ArticleCategoriesDDLRepository();
           
        }

        /// <summary>
        /// Zwraca ArticleCategoriesDDL dla nowego formularza
        /// </summary>
        /// <returns>Pełna lista ArticleCategoriesDDL</returns>
        public List<ArticleCategoriesDDLFormV> ReturnArticleCategoriesDDLForm()
        {
            try
            {
                //using (ArticleCategoriesDDLRepository r = new ArticleCategoriesDDLRepository(_context))
                //{

                //    var linq = from x in r.GetQuery<ArticleCategoriesDDLSearchV>()
                //               select new
                //               {
                //                   x.DepthLevel
                //               };
                //}
                return _articleCategoriesDDLRepository.GetArticleCategoriesDDLForm();
            }            
            catch (Exception ex)
            {
                InformationException = InformationUserDictionary.Instance.GetInformationExceptionText(2) + ex.Message;
                return null;
            }

        }

        /// <summary>
        /// Zwraca ArticleCategoriesDDL dla modyfikowanego formularza
        /// </summary>
        /// <returns>Lista ArticleCategoriesDDL</returns>
        public List<ArticleCategoriesDDLFormV> ReturnArticleCategoriesDDLFormByNotArticleCategoryID(int pArticleCategoryID)
        {
            try
            {
                return _articleCategoriesDDLRepository.GetArticleCategoriesDDLFormByNotArticleCategoryID(pArticleCategoryID);
            }
            catch (Exception ex)
            {
                InformationException = InformationUserDictionary.Instance.GetInformationExceptionText(2) + ex.Message;
                return null;
            }

        }

        /// <summary>
        /// Zwraca ArticleCategoriesDDL dla grida (pole do wyszukania)
        /// </summary>
        /// <returns>Lista urzytych kategorii nadrzędnych ArticleCategoriesDDL</returns>
        public List<ArticleCategoriesDDLSearchV> ReturnArticleCategoriesDDLSearch()
        {
            try
            {
                return _articleCategoriesDDLRepository.GetArticleCategoriesDDLSearch();
            }
            catch (Exception ex)
            {
                InformationException = InformationUserDictionary.Instance.GetInformationExceptionText(2) + ex.Message;
                return null;
            }
        }
    }
}
